package com.haoyeteng.sxbd.core.util;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

/**
 * 面向web层的工具类
 * 
 * @author 理想
 *
 */
public class WebUtils {
	private WebUtils() {

	}

	public static String encodeFileName(HttpServletRequest request, String fileName)
			throws UnsupportedEncodingException {
		String encodedFileName = null;
		String useragent = request.getHeader("USER-AGENT");
		if (useragent != null && (useragent.indexOf("MSIE") != -1 || useragent.indexOf("Trident") != -1)) {// ie
			encodedFileName = java.net.URLEncoder.encode(fileName, "UTF8");
		} else {// firefox,chrome,safari等
			encodedFileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
		}
		return encodedFileName;
	}
}
